// cnpm install --global gulp
import gulp from 'gulp'
import sass from 'gulp-sass'
import gutil from 'gulp-util'
import autoprefixer from 'gulp-autoprefixer'
import babel from 'gulp-babel'
import imagemin from 'gulp-imagemin'
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;


gulp.task('css', () => {
    return gulp.src('./app/assets/_src/styles/**/*.*')
        .pipe(autoprefixer({ browsers: ['last 2 versions', 'Android >= 4.0'], cascade: false }).on('error', gutil.log))
        .pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
        .pipe(gulp.dest('./app/assets/styles'));
        
});

gulp.task('js', () => {
    return gulp.src('./app/assets/_src/scripts/**/*.js')
        .pipe(babel({ presets: ['es2015'], minified: true, sourceMap: true, }))
        .pipe(gulp.dest('./app/assets/scripts'));
});

gulp.task('image', () => {
    return gulp.src('./app/assets/_src/images/**/*.(jpg|png|gif)')
        .pipe(imagemin())
        .pipe(gulp.dest('./app/assets/images'));
});

gulp.task('sass', ['css'], function() {
    gulp.watch("./app/assets/_src/styles/**/*.*", ['css']);
    gulp.watch("app/*.html").on('change', reload);
});

gulp.task('default', ['css', 'js', 'image']);